home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Rounding a double
- Date: Tue, 02 Apr 96 12:49:44 GMT
- Organization: none
- Message-ID: <828449384snz@genesis.demon.co.uk>
- References: <4jprh2$1li@newsgate.dircon.co.uk> <4jq5u5INN80u@mayne.ugrad.cs.ubc.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4jq5u5INN80u@mayne.ugrad.cs.ubc.ca>
- c2a192@ugrad.cs.ubc.ca "Kazimir Kylheku" writes:
-
- >In article <4jprh2$1li@newsgate.dircon.co.uk>,
- >Peter Smith <pg-smith@dircon.co.uk> wrote:
- > >Has anybody got a C function to round a double to a number of decimal
- > >places that:
- > >a) is readable
- > >b) is relatively short
- > >c) works !!
- >
- >double round(double x, int digits)
- >
- >{
- > char buffer[20];
- > sprintf(buffer,"%8.8f",x);
- >
- > buffer >>= (8 - digits);
- >
- > return atof(buffer);
- >}
-
- There was a requirement here that it works! :-)
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-